package action.contract;

import java.sql.Timestamp;
import java.util.List;

import model.company.Companybasic;
import model.company.Companycontact;
import model.company.Companytopmanager;
import model.credit.Creditapplyenterprise;
import model.credit.Creditapplypersonal;
import model.personal.Personalbasic;

import service.app.CreatKeyService;
import service.contract.ContractService;
import util.Time;
import util.Tool;
import util.Sessions;

import core.action.BaseAction;
import exception.Exceptions;

public class ContractListAction extends BaseAction{
	private List<?> menu_name;
	private String page_show;
	private int creditid;
	private int clientid;
	private String contractY;//xx年（合同编号）
	private Integer contractN;//编号
	private Double applymoney;//借款金额
	private String loanpurpose;//借款用途
	private String customname;//借款人名称
	private String address;//地址
	private String phone;//电话
	private String modeofrepayment;//还款方式
	private String fax;//传真
	private Double applybaserate;//基准利率
	private Double slidingscale;//浮动比例
	private Double performrates;//执行利率
	private String Legalrepresentative;//法人代表
	private String position;//法人代表所任职务
	private ContractService contractService;
	private CreatKeyService creatKeyService;
	private String flag;
	private String F;
	private String title;
	@Override
	public String execute(){
		return "success";
	}
	public String showcontract_company(){
		menu_name=contractService.get_credit_list("Companybasic","Creditapplyenterprise","organizationcode");
		flag="company";
		title="企业合同生成";
		return "success";
		}
	public String showcontract_personal(){
		menu_name=contractService.get_credit_list("Personalbasic","Creditapplypersonal","certificatenumber");
		flag="personal";
		title="个人合同生成";
		return "success";
	}
	
	public String contract_companyCreate() throws Exceptions{
		Creditapplyenterprise creditcompany=contractService.get_creditcompany(creditid);
		clientid=creditcompany.getClientid();
		contractY=Time.Timestamp2YearString();
		contractN=creatKeyService.creatKeyOnly(312);
		Companybasic company=new Companybasic();
		company=contractService.get_companybasic(clientid);
		Companycontact companycontact=contractService.get_companycontact(clientid);
		customname=company.getName();
		address=company.getRegaddress();
		phone=companycontact.getTelephone();
		fax=companycontact.getFax();
		Companytopmanager topmanager=contractService.get_topmanager("cid="+company.getId()+"and category=1");
		Legalrepresentative=topmanager.getName();
		position="法人代表";
		applymoney=creditcompany.getLoanaccount();
		loanpurpose=creditcompany.getLoanuse();
		modeofrepayment=creditcompany.getModeofrepayment();
		applybaserate=creditcompany.getApplybaserate();
		slidingscale=creditcompany.getSlidingscale();
		performrates=creditcompany.getPerformrates();
		F="2";
		Sessions.set("creditid",creditid);
		
		successResultValue="../contract/contractLoan";
		return "function";
		}
	public String contract_personalCreate() throws Exceptions{
		
		Creditapplypersonal creditpersonal=contractService.get_creditpersonal(creditid);
		clientid=creditpersonal.getClientid();
		contractY=Time.Timestamp2YearString();
		contractN=creatKeyService.creatKeyOnly(312);
		Personalbasic personal=new Personalbasic();
		personal=contractService.get_personalbasic(creditpersonal.getClientid());
		customname=personal.getName();
		address=personal.getCurrentresidentialaddress();
		phone=personal.getHomephone();
		fax="";	
		Legalrepresentative="";
		position="";
		applymoney=creditpersonal.getLoanaccount();
		loanpurpose=creditpersonal.getLoanuse();
		modeofrepayment=creditpersonal.getModeofrepayment();
		applybaserate=creditpersonal.getApplybaserate();
		slidingscale=creditpersonal.getSlidingscale();
		performrates=creditpersonal.getPerformrates();
		F="1";
		Sessions.set("creditid",creditid);
		
		successResultValue="../contract/contractLoan";
		return "function";
	}
	public String ContractAudit(){
		flag="audit";
		successResultValue="../contract/contractLoan";
		return "function";
	}
	
	public ContractService getContractService() {
		return contractService;
	}
	public void setContractService(ContractService contractService) {
		this.contractService = contractService;
	}


	public int getCreditid() {
		return creditid;
	}

	public void setCreditid(int creditid) {
		this.creditid = creditid;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}
	public List<?> getMenu_name() {
		return menu_name;
	}
	public void setMenu_name(List<?> menu_name) {
		this.menu_name = menu_name;
	}
	public String getPage_show() {
		return page_show;
	}
	public void setPage_show(String page_show) {
		this.page_show = page_show;
	}
	public String getCustomname() {
		return customname;
	}
	public void setCustomname(String customname) {
		this.customname = customname;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getFax() {
		return fax;
	}
	public void setFax(String fax) {
		this.fax = fax;
	}
	public int getClientid() {
		return clientid;
	}
	public void setClientid(int clientid) {
		this.clientid = clientid;
	}
	public String getContractY() {
		return contractY;
	}
	public void setContractY(String contractY) {
		this.contractY = contractY;
	}
	public Double getApplymoney() {
		return applymoney;
	}
	public void setApplymoney(Double applymoney) {
		this.applymoney = applymoney;
	}
	public String getLoanpurpose() {
		return loanpurpose;
	}
	public void setLoanpurpose(String loanpurpose) {
		this.loanpurpose = loanpurpose;
	}
	public String getModeofrepayment() {
		return modeofrepayment;
	}
	public void setModeofrepayment(String modeofrepayment) {
		this.modeofrepayment = modeofrepayment;
	}
	public Double getApplybaserate() {
		return applybaserate;
	}
	public void setApplybaserate(Double applybaserate) {
		this.applybaserate = applybaserate;
	}
	public Double getSlidingscale() {
		return slidingscale;
	}
	public void setSlidingscale(Double slidingscale) {
		this.slidingscale = slidingscale;
	}
	public Double getPerformrates() {
		return performrates;
	}
	public void setPerformrates(Double performrates) {
		this.performrates = performrates;
	}
	public String getLegalrepresentative() {
		return Legalrepresentative;
	}
	public void setLegalrepresentative(String legalrepresentative) {
		Legalrepresentative = legalrepresentative;
	}
	public String getPosition() {
		return position;
	}
	public void setPosition(String position) {
		this.position = position;
	}
	public Integer getContractN() {
		return contractN;
	}
	public void setContractN(Integer contractN) {
		this.contractN = contractN;
	}
	public CreatKeyService getCreatKeyService() {
		return creatKeyService;
	}
	public void setCreatKeyService(CreatKeyService creatKeyService) {
		this.creatKeyService = creatKeyService;
	}
	public String getF() {
		return F;
	}
	public void setF(String f) {
		F = f;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
}
